package com.ae;

import com.ae.counter.QuackCounter;
import com.ae.factory.AbstractDuckFactory;
import com.ae.factory.CountingDuckFactory;
import com.ae.flock.Flock;
import com.ae.geese.Goose;
import com.ae.geese.GooseAdaptor;

public class DuckSimulator {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		DuckSimulator simulator = new DuckSimulator(); 
		AbstractDuckFactory duckFactory = new CountingDuckFactory();
		simulator.simulate(duckFactory); 

	}

	private void simulate(AbstractDuckFactory duckFactory) {
		Quackable mallardDuck = duckFactory.createMallardDuck() ;
		Quackable redheadDuck = duckFactory.createRedheadDuck(); 
		Quackable duckCall = duckFactory.createDuckCall() ;
		Quackable rubberDuck = duckFactory.createRubberDuck(); 
		
		// ** Added
		Quackable gooseDuck = new GooseAdaptor(new Goose() ) ;
		
		
		System.out.println(" Duck simulator with Flocks is started \n\n");
		
		
		// Total Flock is generated
		
		Flock flockOfDucks = new Flock(); 
		
		flockOfDucks.add(redheadDuck);
		flockOfDucks.add(duckCall);
		flockOfDucks.add(rubberDuck);			
		flockOfDucks.add(gooseDuck);

		// Mallard flock is generated
		Quackable mallardOne = duckFactory.createMallardDuck();
		Quackable mallardTwo = duckFactory.createMallardDuck();
		Quackable mallardThree = duckFactory.createMallardDuck();
		Quackable mallardFour = duckFactory.createMallardDuck();
		
		Flock flockOfMallard = new Flock(); 
		
		flockOfMallard.add(mallardOne);
		flockOfMallard.add(mallardTwo);
		flockOfMallard.add(mallardThree);			
		flockOfMallard.add(mallardFour);

		flockOfDucks.add(flockOfMallard);
		
		
		System.out.println("==================================");
		System.out.println(" Duck Simulator : Whole Flock     ");
		System.out.println("==================================");
		simulate(flockOfDucks);
		
		System.out.println("==================================");
		System.out.println(" Duck Simulator : Mallard Flock   ");
		System.out.println("==================================");
		simulate(flockOfMallard);
		
		System.out.println("\n\n");
		System.out.println("The ducks quacked " + QuackCounter.getQuacks() + " times");
		
	}

	private void simulate() {
		Quackable mallardDuck = new QuackCounter( new MallardDuck() ); 
		Quackable redheadDuck = new QuackCounter( new RedheadDuck() ); 
		Quackable duckCall = new QuackCounter( new DuckCall() ); 
		Quackable rubberDuck = new QuackCounter( new RubberDuck() ); 
		
		// ** Added
		Quackable gooseDuck = new GooseAdaptor(new Goose() ) ;
		
		System.out.println("=============================");
		System.out.println(" Duck simulator is simulated ");
		System.out.println("=============================\n\n");
		
		simulate(mallardDuck);
		simulate(redheadDuck);
		simulate(duckCall);
		simulate(rubberDuck);			
		// ** Added
		simulate(gooseDuck);
		
		System.out.println("\n"); 
		System.out.println("The ducks quacked " + QuackCounter.getQuacks() + " times");
	}
	
	void simulate(Quackable duck) {
		duck.quack();
	}

}
